<?php
class UsersController extends Controller
{
	public function addAction()
	{
		$usersModel = V::M('users');
		$usersModel->user_loginname = 'vivo1000';
		$usersModel->user_password = '111111';
		$usersModel->group_id = '1';
		$usersModel->user_nicename = 'vivo1000';
		$usersModel->user_email = 'vivo1000@vivo.com';
		$usersModel->user_status = 'y';
		
		$usersModel->save();
		
		$user = $usersModel->load('vivo1000', 'user_loginname');
		echo '<pre>';
		print_r($user);
		exit;
	}
	
	public function loadAction()
	{
		V::M('users')->load(2);
		echo 'user_loginname: ', V::M('users')->user_loginname, '<br/>';
		echo 'user_nicename: ', V::M('users')->user_nicename, '<br/>';
		echo 'user_email: ', V::M('users')->user_email, '<br/>';
		exit;
	}
	
	public function editAction()
	{
		$usersModel = V::M('users');
		$usersModel->load(2);
		$usersModel->user_loginname = 'vivo';
		$usersModel->user_nicename = 'vivo';
		$usersModel->user_email = 'vivo@yeah.net';
		$usersModel->save();
		
		echo '<pre>';
		$fields = $usersModel->getSelectFields();
		unset($fields['user_password']);
		$users = $usersModel->getAdapter()->fields($fields)->where(array('user_id = ?', 2))->find();
		print_r($users);
		exit;
	}
	
	public function loginAction()
	{
		$_POST['user_loginname'] = 'vivo1000';
		$_POST['user_password'] = '111111';
		$usersModel = V::M('users');
		$where = array('user_loginname = ? AND user_password = ?', $_POST['user_loginname'], $_POST['user_password']);
		$row = $usersModel->load($where);
		
		if ($row)
		{
			$usersModel->dt_last_login = date('Y-m-d H:i:s');
			$usersModel->ip_last_login = Helper::getIp();
			$usersModel->save();
		}
		
		echo '<pre>';
		$fields = $usersModel->getSelectFields();
		unset($fields['user_password']);
		$users = $usersModel->getAdapter()->fields($fields)->where(array('user_loginname = ?', $_POST['user_loginname']))->find();
		print_r($users);
		exit;
	}
} 
